package leetcode.part1;

import org.junit.Test;

public class S14 {
    public String longestCommonPrefix(String[] strs) {
        String prefix=strs[0];
        for (int i = 1; i < strs.length; i++) {
            StringBuilder builder=new StringBuilder();
            int len=Math.min(prefix.length(),strs[i].length());
            for (int j = 0; j < len; j++) {
                if (strs[i].charAt(j)==prefix.charAt(j)){
                    builder.append(prefix.charAt(j));
                }else {
                    break;
                }

            }
            prefix=builder.toString();
        }
        return prefix;
    }
    @Test
    public void test(){
        String[] str={"flower","flow","flight"};
        String s = longestCommonPrefix(str);
        System.out.println(s);
    }
}
